/**
 * 
 */
package info.niwota.webshot;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Vibrator;

/**
 * @author qiangli
 * 
 */
public final class Notifications {

	private static Vibrator vibrator;

	private Notifications() {
	}

	private static final int SERVICE_ID = R.string.app_name;

	private static final int NOTE_TITLE = R.string.app_name;

	public static void add(Context ctx, Class<?> clz, int res) {
		Notification note = new Notification(R.drawable.icon, null, 0);
		PendingIntent pi = PendingIntent.getActivity(ctx, 0, new Intent(ctx,
				clz), 0);
		note.flags |= Notification.FLAG_NO_CLEAR;
		note.flags |= Notification.FLAG_ONGOING_EVENT;
		//
		CharSequence title = ctx.getText(NOTE_TITLE);
		CharSequence desc = ctx.getText(res);
		note.setLatestEventInfo(ctx, title, desc, pi);
		NotificationManager nm = (NotificationManager) ctx
				.getSystemService(Context.NOTIFICATION_SERVICE);
		nm.notify(SERVICE_ID, note);
	}

	public static void remove(Context ctx) {
		NotificationManager nm = (NotificationManager) ctx
				.getSystemService(Context.NOTIFICATION_SERVICE);
		nm.cancelAll();
	}
	
	public static void vibrate(Context ctx) {
		if (vibrator == null) {
			vibrator = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
		}
		vibrator.vibrate(100);
	}
}
